<template>
	<view class="examine-container">
		<view class="examine-list mb24">
			<view class="examine-item">
				<view class="examine-head">
					<text class="label">招聘考试</text>
					<text class="sub-title">{{ details.recruitTitle }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">单位名称： </text>
					<text class="label-value">{{ details.employer }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">岗位名称：</text>
					<text class="label-value">{{ details.positionName }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">姓 名： </text>
					<text class="label-value">{{ details.fullName }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">联系方式： </text>
					<text class="label-value">{{ details.contactInformation }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">报名时间： </text>
					<text class="label-value">{{ details.registrationTime }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">报考编码： </text>
					<text class="label-value">{{ details.recCode }}</text>
				</view>
				<view class="info-item">
					<text class="label-tip">考试状态： </text>
					<!-- <text :class="['status', mapAuditStatus(details.auditStatus).class]">{{ mapAuditStatus(details.auditStatus).text }}</text> -->
					<view class="">
						<text :class="['status', mapAuditStatus(details.auditStatus).class]">{{ mapAuditStatus(details.auditStatus).text }}</text>
						<view class="fail-reson" v-if="details.auditStatus == 2 || details.auditStatus == 6">
							<view style="color: #FF7F1C;font-size: 24rpx;">{{ details.auditOpinion }}</view>
							<view style="color: #FF7F1C;font-size: 24rpx;">{{ details.auditTime }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 3审核通过，请缴纳报名费 -->
		<view class="pay-wrap" v-if="details.auditStatus === 3 || details.auditStatus === 6">
			<view class="common-title mb20">缴费说明</view>
			<view class="pay-tip">
				付款考生缴费时须<text
					style="color: #FF7F1C;">备注考生姓名、电话号码</text>等信息，缴费成功即为报名成功，逾期未缴费者，视为自动放弃，所造成的一切损失由报考者本人承担。本次招聘除应聘岗位取消情况外，概不办理退费手续。
			</view>
			<view class="pay-date">
				缴费截止时间为：2025年4月30日 12:00
			</view>

			<view class="pay-image">
				<image :src="api_host + details.payQrcode" mode="widthFix"></image>
			</view>

			<view class="common-title mb32">缴费证明</view>
			<image v-if="imgUrl" class="payed-img" :src="imgUrl" mode=""></image>
			<view class="upload-box">
				<button class="upload-btn" @tap="uploadImage">{{ imgUrl ? '重新上传缴费证明' : '上传缴费证明' }}</button>
			</view>
		</view>

		<!-- 7请下载笔试准考证 -->
		<view class="pay-wrap" v-if="details.auditStatus === 7">
			<view class="common-title mb20">考试安排</view>
			<view class="examine-info">
				<view class="examine-date">
					<text>笔试时间</text>
					<text class="fw600">{{ details.examTime }} {{ details.startTime + '-' + details.endTime }}</text>
				</view>

				<view class="examine-address">
					<text>考试地点</text>
					<text class="fw600">{{ details.venueAddr }}</text>
				</view>
			</view>

			<view class="upload-box">
				<button class="upload-btn" @click="handleNavTo">考试地址导航</button>
			</view>
		</view>
		<view v-if="details.auditStatus === 7" class="examine-tip">
			* 请下载准考证并打印出来，考试当天携带准考证、身份证进入考场。
		</view>
		
		<!-- 8查看成绩 -->
		<view class="pay-wrap" v-if="details.auditStatus === 8">
			<view class="common-title mb20">考试成绩</view>
			<view class="examine-info">
				<text>请前往黄石人才网查看笔试成绩</text>
				<text>
					查询网址：<text style="display: inline;color: deepskyblue;">www.hsrcsc.com</text>
				</text>
			</view>
		
			<view class="upload-box">
				<button class="upload-btn" @tap="handleCopy">复制网址</button>
			</view>
		</view>
		


		<view class="btn-wrap" v-if="details.auditStatus === 3 || details.auditStatus === 6">
			<button class="result-btn" @tap="handleSaveImg">保存缴费二维码</button>
			<button class="examine-btn" @tap="handleSendPayData">提交缴费证明</button>
		</view>

		<view class="btn-wrap edit-wrap" v-if="details.auditStatus === 2">
			<button class="apply-btn" @tap="editApplyForm">修改报名表</button>
		</view>
		
		<!-- 准考证模板 -->
		<drawticket v-if="details.auditStatus === 7" ref="drawTicket" :detail="details"></drawticket>
		
		<view class="btn-wrap edit-wrap" v-if="details.auditStatus === 7">
			<button class="apply-btn" @tap="handleDownLoadPass">下载准考证</button>
		</view>
		
		<!-- <u-modal :show="show" :title="title" :content='content'></u-modal> -->
		
	</view>
</template>

<script>
	import {
		enrollUserInfo,
		sendPayData
	} from '@/common/api_examine.js'
	import drawticket from './drawticket.vue'
	export default {
		data() {
			return {
				details: {},
				imgUrl: '',
			}
		},
		components: {
			drawticket
		},
		onLoad(option) {
			this.getDetail(option.id)
		},
		methods: {
			async getDetail(id) {
				const res = await enrollUserInfo(id)
				if (res.code === 200) {
					this.details = res.data
					this.imgUrl = res.data.payProves
					// this.details.auditStatus = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
				}
			},
			uploadImage() {
				const that = this
				uni.chooseImage({
					count: 1,
					success: (res) => {
						res.tempFilePaths.forEach(async file => {
							const res1 = await that.$utils.uploadFile(file)
							if (res1.code == 200) {
								that.imgUrl = res1.url
								console.log(that.imgUrl, 'that.imgList')
							}
						})
					}
				});
			},
			// 复制网址
			handleCopy() {
				uni.setClipboardData({
					data: 'www.hsrcsc.com',
					success() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			},
			// 提交缴费证明
			async handleSendPayData() {
				if (!this.imgUrl) {
					uni.showToast({
						title: '请上传缴费证明',
						icon: 'none'
					})
					return
				}
				const res = await sendPayData({
					id: this.details.id,
					payProves: this.imgUrl
				})
				if (res.code === 200) {
					uni.showToast({
						title: '缴费成功, 请等待审核！',
						icon: 'none'
					})
					uni.navigateBack()
				}
			},
			handleSaveImg() {
				// let poster = this.api_host + this.info.imageShare
				let that = this
				uni.downloadFile({
					url: 'http://101.34.111.187:8085/profile/upload/2025/04/23/92c47f28658b45f7aa01623d9f1d6a92_20250423142850A010.png', //仅为示例，并非真实的资源
					success: (res) => {
						let tempFilePath = res.tempFilePath
						// //获取授权列表，查看是否授权写入相册权限
						uni.getSetting({
							success(res1) {
								if (!res1.authSetting['scope.writePhotosAlbum']) {
									uni.authorize({
										scope: 'scope.writePhotosAlbum',
										success() {
											that.saveimgtoAlbum(tempFilePath)
										}
									})
								} else {
									that.saveimgtoAlbum(tempFilePath)
								}
							}
						})
					}
				});
			},
			saveimgtoAlbum(imgurl) {
				//图片保存到本地
				let that = this
				uni.showLoading()
				uni.saveImageToPhotosAlbum({
					filePath: imgurl,
					success: function(data) {
						uni.hideLoading()
						uni.showToast({
							title: '保存成功',
							icon: 'success',
							duration: 2000
						})
					},
					fail: function(err) {
						uni.hideLoading()
						if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
							uni.openSetting({
								success(settingdata) {
									if (settingdata.authSetting['scope.writePhotosAlbum']) {
										uni.showToast({
											title: '您已授权成功，请重新保存海报',
											icon: 'success',
											duration: 2000
										})
									} else {
										uni.showToast({
											title: '尚未授权，无法保存海报',
											icon: 'none',
											duration: 2000
										})
									}
								}
							})
						}
					},
					complete(res) {
						console.log(res);
					}
				})

			},
			mapAuditStatus(type) {
				// 1等待报名审核 2审核不通过 3审核通过，请缴纳报名费 4审核通过，请等待考试安排 5缴费成功，请等待考试安排 6缴费不通过 7请下载笔试准考证 8查看成绩
				switch (type) {
					case 1:
						return {
							class: 'wait',
							text: '等待报名审核'
						}
					case 2:
						return {
							class: 'fail',
							text: '审核不通过'
						}
					case 3:
						return {
							class: 'pass',
							text: '审核通过，请缴纳报名费'
						}
					case 4:
						return {
							class: 'pass',
							text: '审核通过，请等待考试安排'
						}
					case 5:
						return {
							class: 'pass',
							text: '缴费成功，请等待考试安排'
						}
					case 6:
						return {
							class: 'fail',
							text: '缴费失败，请重新上传缴费证明'
						}
					case 7:
						return {
							class: 'wait',
							text: '请下载笔试准考证'
						}
					case 8:
						return {
							class: 'wait',
							text: '查看成绩'
						}
					case 9:
						return {
							class: 'wait',
							text: '缴费证明审核中'
						}
				}
				
			},
			// 导航
			handleNavTo() {
				console.log('handleNavTo', this.details)
				uni.openLocation({
					latitude: Number(this.details.latitude),
					longitude: Number(this.details.longitude),
					name: this.details.venueName,
					address: this.details.venueAddr,
				})
			},
			// 下载准考证
			handleDownLoadPass() {
				this.$refs.drawTicket.saveImg()
			},
			// 修改报名表
			editApplyForm() {
				uni.navigateTo({
					url: `/subpage/examine/applyform?id=${this.details.recId}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.examine-container {
		position: relative;
		min-height: 100vh;
		padding: 24rpx 32rpx 32rpx;
		background: #F2F5FF;
		box-sizing: border-box;
		

		.examine-list {
			.examine-item {
				width: 100%;
				padding: 30rpx 28rpx 28rpx 32rpx;
				box-sizing: border-box;
				border-radius: 40rpx;
				background-color: #fff;

				.examine-head {
					margin-bottom: 4rpx;

					.label {
						display: inline-block;
						padding: 6rpx 12rpx;
						margin-right: 12rpx;
						font-size: 22rpx;
						color: #34314F;
						line-height: 24rpx;
						text-align: center;
						background: #F0F0F2;
						border-radius: 12rpx;
					}

					.sub-title {
						font-weight: 600;
						font-size: 32rpx;
						color: #34314F;
						line-height: 44rpx;
						text-align: left;
					}
				}

				.examine-title {
					margin-bottom: 16rpx;
					font-weight: 600;
					font-size: 32rpx;
					color: #34314F;
					line-height: 44rpx;
					text-align: left;


				}

				.info-item {
					display: flex;
					margin-bottom: 24rpx;

					.label-tip {
						min-width: 130rpx;
						font-weight: 400;
						font-size: 26rpx;
						color: #9A98A7;
						line-height: 22px;
						font-style: normal;
						text-align: justify;
						text-align-last: justify
					}

					.label-value {
						font-weight: 400;
						font-size: 26rpx;
						color: #34314F;
						line-height: 22px;
						text-align: left;
						font-style: normal;
					}

					.status {
						font-weight: 600;
						font-size: 26rpx;
						line-height: 22px;
						text-align: left;
						font-style: normal;

						&.wait {
							color: #FF7F1C;
						}

						&.fail {
							color: #34314F;
						}

						&.pass {
							color: #1FBF70;
						}
					}
				}


			}
		}

		.pay-wrap {
			width: 100%;
			padding: 30rpx 28rpx 40rpx 32rpx;
			box-sizing: border-box;
			border-radius: 40rpx;
			background-color: #fff;

			.common-title {
				font-weight: 600;
				font-size: 32rpx;
				color: #34314F;
				line-height: 44rpx;
				text-align: left;
			}
			
			.examine-info {
				.examine-date {
					margin-bottom: 40rpx;
				}
				text {
					display: block;
					font-weight: 400;
					font-size: 26rpx;
					color: #34314F;
					line-height: 44rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.pay-tip {
				margin-bottom: 12rpx;
				font-size: 26rpx;
				color: #34314F;
				line-height: 44rpx;
				text-align: left;
				font-style: normal;
			}

			.pay-date {
				margin-bottom: 36rpx;
				font-size: 26rpx;
				color: #FF7F1C;
				line-height: 44rpx;
				text-align: left;
				font-style: normal;
			}

			.pay-image {
				margin-bottom: 48rpx;

				image {
					display: block;
					width: 100%;
					// height: 100%;
					margin: 0 auto;
				}
			}

			.upload-box {
				margin-top: 50rpx;

				.upload-btn {
					width: 276rpx;
					height: 72rpx;
					background: #F7F7F7;
					border-radius: 36rpx;
					border: 1px solid #ECECEC;

					font-weight: 600;
					font-size: 28rpx;
					color: #34314F;
					line-height: 72rpx;
					text-align: center;

					&::after {
						border: 0;
					}
				}
			}
		}

		
		.examine-tip {
			margin-top: 24rpx;
			font-weight: 400;
			font-size: 26rpx;
			color: #34314F;
			line-height: 44rpx;
			text-align: left;
			font-style: normal;
		}
		.btn-wrap {
			// bottom: 28rpx;
			// right: 28rpx;
			display: flex;
			margin-top: 40rpx;
			margin-bottom: 40rpx;

			&.edit-wrap {
				position: absolute;
				bottom: 40rpx;
				left: 32rpx;
				width: calc(100% - 64rpx);

			}

			.result-btn {
				width: 340rpx;
				height: 80rpx;
				margin: 0;
				background: #34314F;
				border-radius: 40px;
				text-align: center;
				font-weight: 600;
				font-size: 14px;
				color: #fff;
				line-height: 80rpx;
				font-style: normal;
				box-sizing: border-box;

				&::after {
					border: 0;
				}
			}

			.examine-btn {
				width: 340rpx;
				height: 80rpx;
				margin: 0 0 0 28rpx;
				background: #FFDE6D;
				border-radius: 40px;
				text-align: center;
				font-weight: 600;
				font-size: 14px;
				color: #34314F;
				line-height: 80rpx;
				font-style: normal;
				box-sizing: border-box;

				&::after {
					border: 0;
				}
			}

			.apply-btn {
				width: 100%;
				height: 96rpx;
				margin: 0;
				background: #FFDE6D;
				border-radius: 40px;
				text-align: center;
				font-weight: 600;
				font-size: 14px;
				color: #34314F;
				line-height: 96rpx;
				font-style: normal;
				box-sizing: border-box;

				&::after {
					border: 0;
				}
			}
		}
	}
</style>